package com.kgc.kmall.managerservice.service;

import com.kgc.kmall.bean.PmsSkuAttrValue;
import com.kgc.kmall.bean.PmsSkuImage;
import com.kgc.kmall.bean.PmsSkuInfo;
import com.kgc.kmall.bean.PmsSkuSaleAttrValue;
import com.kgc.kmall.managerservice.mapper.PmsSkuAttrValueMapper;
import com.kgc.kmall.managerservice.mapper.PmsSkuImageMapper;
import com.kgc.kmall.managerservice.mapper.PmsSkuInfoMapper;
import com.kgc.kmall.managerservice.mapper.PmsSkuSaleAttrValueMapper;
import com.kgc.kmall.service.SkuService;
import org.apache.dubbo.config.annotation.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SkuServiceImpl implements SkuService {
    @Resource
    PmsSkuInfoMapper pmsSkuInfoMapper;
    @Resource
    PmsSkuAttrValueMapper pmsSkuAttrValueMapper;

    @Resource
    PmsSkuImageMapper pmsSkuImageMapper;

    @Resource
    PmsSkuSaleAttrValueMapper pmsSkuSaleAttrValueMapper;

    @Override
    public int saveSkuInfo(PmsSkuInfo pmsSkuInfo) {
        System.out.println(pmsSkuInfo.toString());
        int insert = pmsSkuInfoMapper.insert(pmsSkuInfo);
        Long pmsSkuInfoId = pmsSkuInfo.getId();
        List<PmsSkuAttrValue> skuAttrValueList = pmsSkuInfo.getSkuAttrValueList();
        if(skuAttrValueList!=null&&skuAttrValueList.size()>0){
            pmsSkuAttrValueMapper.addPmsSkuAttrValue(pmsSkuInfoId,skuAttrValueList);
        }

        List<PmsSkuImage> skuImageList = pmsSkuInfo.getSkuImageList();
        if(skuImageList!=null&&skuImageList.size()>0){
            pmsSkuImageMapper.addPmsSkuImage(pmsSkuInfoId,skuImageList);
        }

        List<PmsSkuSaleAttrValue> skuSaleAttrValueList = pmsSkuInfo.getSkuSaleAttrValueList();
        if(skuSaleAttrValueList!=null&&skuSaleAttrValueList.size()>0){
            pmsSkuSaleAttrValueMapper.addPmsSkuSaleAttrValue(pmsSkuInfoId,skuSaleAttrValueList);
        }

        return insert;
    }

    @Override
    public PmsSkuInfo selectBySkuId(Long skuId) {
        return pmsSkuInfoMapper.selectByPrimaryKey(skuId);
    }


}
